﻿package igz.fleaxy.ui.menu
{
	import flash.display.Sprite;
	import igz.fleaxy.pattern.Dto;
	
	/**
	 * @author Intelygenz | www.intelygenz.com
	 * 
	 * Clase que contendrá un AbstractMenuUi y todos sus elementos. Tiene un AbstractMenuUi y un conjunto de elementos.
	 * 
	 */
	public class AbstractMenuContainerUi extends Sprite {
		
		protected var _Items:Array;
		public function get $Items():Array {
			return _Items;
		}
		
		protected var _MenuUi:AbstractMenuUi;
		
		protected var _ItemParentUi:AbstractMenuItemUi;
		
		public function set $ItemParentUi( p_itemParentUi:AbstractMenuItemUi ):void {
			_ItemParentUi = p_itemParentUi;
		}
		public function get $ItemParentUi():AbstractMenuItemUi {
			return _ItemParentUi;
		}
		
		public function AbstractMenuContainerUi( p_menuUi:AbstractMenuUi ) {
			_Items  = new Array();
			_MenuUi = p_menuUi;
		}
		
		public function $AddItem( p_itemDto:Dto, p_itemType:Class ):void {
			_Items.push( new p_itemType(this, p_itemDto ) );	
		}
	
		public function $Hide():void {
			visible = false;
		}

		public function $Show():void {			
			visible = true;
		}
	
		protected function _HideVisibleChilds() : void {
			var visibleChild:AbstractMenuContainerUi = _MenuUi.$ContainerActivo as AbstractMenuContainerUi;
			if ( ( visibleChild != null ) && (this.$ItemParentUi != null ) ) {
				while ( visibleChild != this.$ItemParentUi.$MyContainerUi ) {
					visibleChild.$Hide();
					if ( ( visibleChild.$ItemParentUi != null ) && ( visibleChild.$ItemParentUi.$MyContainerUi != null ) ) {
						visibleChild = visibleChild.$ItemParentUi.$MyContainerUi as AbstractMenuContainerUi;
					}
					else {
						visibleChild = this;
					}
				}
			}
		}
		
		public function $Disable () : void {
			var item : AbstractMenuItemUi;
			for each ( item in _Items ) {
				item.$Disable();
			}
		}
		
		public function $Enable () : void {
			var item : AbstractMenuItemUi;
			for each ( item in _Items ) {
				item.$Enable();
			}
		}

	}
	
}